#!/bin/bash

# ------------------------------------------------------------------------------
# 一键导出调试好的MSS数据，并上传到FTP，后续初始化组件从FTP上获取数据初始化到新环境
# ------------------------------------------------------------------------------

current_date=$(date +%Y%m%d)
EXPORT_PATH="/tmp/data_platform"
mkdir -p $EXPORT_PATH
EXPORT_PATH_DDL="$EXPORT_PATH/dp_mss_${current_date}_ddl.sql"
EXPORT_PATH_DML="$EXPORT_PATH/dp_mss_${current_date}_dml.sql"

echo "开始导出 mysql 数据"

echo "导出 mysql ddl 到文件：$EXPORT_PATH_DDL"
/data/package/mysql/mysqldump -hmysql.ahcloud-private.com -P3307 -u$MYSQL_USER -p$MYSQL_PASSWD \
  --no-data --default-character-set=utf8 --databases data_platform \
  > $EXPORT_PATH_DDL

echo "导出 mysql dml 到文件：$EXPORT_PATH_DML"
/data/package/mysql/mysqldump -hmysql.ahcloud-private.com -P3307 -u$MYSQL_USER -p$MYSQL_PASSWD \
--no-create-info --default-character-set=utf8 --databases data_platform \
--ignore-table=data_platform.analysis_statistical_task_compensate \
--ignore-table=data_platform.analysis_table_info \
--ignore-table=data_platform.analysis_task_execute_log \
--ignore-table=data_platform.analysis_record_log \
--ignore-table=data_platform.task_schedule_record \
--ignore-table=data_platform.analysis_detail_rule \
--ignore-table=data_platform.analysis_basic_quota_table \
--ignore-table=data_platform.etl_job_detail \
--ignore-table=data_platform.heartbeat_except \
> $EXPORT_PATH_DML

echo "导出完成，开始上传FTP"

curl -T $EXPORT_PATH_DDL ftp://admin:ci_CcXx_4202ftp@10.20.140.138/mss/data-platform/mysql/
curl -T $EXPORT_PATH_DML ftp://admin:ci_CcXx_4202ftp@10.20.140.138/mss/data-platform/mysql/